/**
 * 典型的斜率优化。但是注意当结尾的仓库的p为零时，未必要在这里建仓库，当然也未必是一定不建。
 * 因此减少P数组是[....p00000]，则答案应该是[p00000]段的最小值。
 */
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

typedef long long llt;
typedef long double Real;

struct Point {
    llt x;
    llt y;
    Point(llt a=0, llt b=0):x(a),y(b){}
    llt cross(const Point & A, const Point & B) const {
        llt xoa = A.x - x, yoa = A.y - y;
        llt xob = B.x - x, yob = B.y - y;
        return xoa * yob - xob * yoa;
    }
    llt cross(const Point & r) const {
        return x * r.y - y * r.x;
    }
    const Point operator - (const Point & r) const {
        return Point(x - r.x, y - r.y);
    } 
};

int N;
vector<llt> X;
vector<llt> SX;
vector<llt> SP;
vector<llt> PX;
vector<llt> C;
vector<llt> D;
vector<int> Q;

const Point get(int p){
    return Point(SP[p], D[p] + PX[p]);
}

void work(){    
    cin >> N;
    X.assign(N + 1, 0);
    SX.assign(N + 1, 0);
    PX.assign(N + 1, 0);
    SP.assign(N + 1, 0);
    C.assign(N + 1, 0);
    D.assign(N + 1, 0);

    for(int x,p,c,i=1;i<=N;++i){
        cin >> X[i] >> p >> C[i];
        SX[i] = SX[i - 1] + (X[i]);
        SP[i] = SP[i - 1] + (p);
        PX[i] = PX[i - 1] + p * X[i];
    }

    Q.assign(N + 1, 0);
    vector<int>::iterator bot = Q.begin();
    vector<int>::iterator top = bot;

    for(int i=1;i<=N;++i){
        const Point now(1, X[i]);
        while(bot < top and now.cross(get(*(bot + 1)) - get(*bot)) <= 0){
            bot += 1;
        }
        D[i] = D[*bot] + X[i] * (SP[i] - SP[*bot]) - PX[i] + PX[*bot] + C[i];
        while(bot < top and get(*(top - 1)).cross(get(*top), get(i)) <= 0){
            top -= 1;
        }
        *++top = i;
    }

    llt ans = D[N];
    for(int i=N-1;i>=0;--i){
        if(SP[i] != SP[i + 1]) break;
        ans = min(ans, D[i]);
    }

    cout << ans << "\n";
    return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}